import random as rd


# Npc
class Npc:  # 父类
    def __init__(self, name, hp):
        self.name = name
        self.hp = hp
        self.skills = {}  # 储存skills_name为key,skill_damage为value

    def skill(self, skill_name, skill_damage):  # 技能字典
        self.skills[skill_name] = skill_damage  # 作为键值对使用

    def attack(self, skill_name, target):  # 攻击
        target.hp -= self.skills[skill_name]  # 目标现血量 = 原血量 - 技能伤害
        return print(f"{self.name}使用技能{skill_name}对{target.name}造成了{self.skills[skill_name]}点伤害!")

    def alive(self):
        return self.hp > 0  # 布尔值判断,判断角色是否存活.在game.py中会用到while进行判断,若死亡则循环结束
# 所以在后续使用alive方法时必须前置循环条件判断


# Hero
class Hero(Npc):  # 继承父类npc
    def __init__(self, name, hp):
        super().__init__(name, hp)
        self.skills["平A"] = 5
        self.skills["大招"] = 30

    def attack(self, skill_name, target):  # 攻击
        return super().attack(skill_name, target)


# Monster
class Monster(Npc):  # 继承npc属性
    def __init__(self, name, hp):
        super().__init__(name, hp)
        self.skills["撕咬"] = 15
        self.skills["爪击"] = 5

    def attack(self, skill_name, target):
        return super().attack(skill_name, target)


# game
hero1 = Hero("英雄1", 100)
monster1 = Monster("小怪", 60)

while hero1.alive() and monster1.alive() is True:  # 循环攻击 同时存活
    print(f"{hero1.name} HP:{hero1.hp}  {monster1.name} HP:{monster1.hp}")
# 显示双方血量
    hero1.attack(rd.choice(hero1.skill()), monster1)
    if monster1.alive() is True:  # 布尔值判断,False时循环结束
        monster1.attack(rd.choice(hero1.skill()), hero1)
        if hero1.alive() is True:
            continue
        else:
            print(f"{hero1}被{monster1}用最后一击{monster1.skill}杀死!")
    else:
        print(f"{monster1}被{hero1}杀死!")
print(f"{hero1}剩余血量{hero1.hp}")
